﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using Dienthoai.Entities;
using Dienthoai.Data;

#endregion

namespace Dienthoai.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="ProductsProductProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class ProductsProductProviderBaseCore : EntityProviderBase<Dienthoai.Entities.ProductsProduct, Dienthoai.Entities.ProductsProductKey>
	{		
		#region Get from Many To Many Relationship Functions
		#region GetByOrdersIdFromOrdersDetails
		
		/// <summary>
		///		Gets Products_Product objects from the datasource by Orders_Id in the
		///		Orders_Details table. Table Products_Product is related to table Orders_Order
		///		through the (M:N) relationship defined in the Orders_Details table.
		/// </summary>
		/// <param name="_ordersId"></param>
		/// <returns>Returns a typed collection of ProductsProduct objects.</returns>
		public TList<ProductsProduct> GetByOrdersIdFromOrdersDetails(System.Int32 _ordersId)
		{
			int count = -1;
			return GetByOrdersIdFromOrdersDetails(null,_ordersId, 0, int.MaxValue, out count);
			
		}
		
		/// <summary>
		///		Gets Dienthoai.Entities.ProductsProduct objects from the datasource by Orders_Id in the
		///		Orders_Details table. Table Products_Product is related to table Orders_Order
		///		through the (M:N) relationship defined in the Orders_Details table.
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_ordersId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of ProductsProduct objects.</returns>
		public TList<ProductsProduct> GetByOrdersIdFromOrdersDetails(System.Int32 _ordersId, int start, int pageLength)
		{
			int count = -1;
			return GetByOrdersIdFromOrdersDetails(null, _ordersId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets ProductsProduct objects from the datasource by Orders_Id in the
		///		Orders_Details table. Table Products_Product is related to table Orders_Order
		///		through the (M:N) relationship defined in the Orders_Details table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_ordersId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Products_Product objects.</returns>
		public TList<ProductsProduct> GetByOrdersIdFromOrdersDetails(TransactionManager transactionManager, System.Int32 _ordersId)
		{
			int count = -1;
			return GetByOrdersIdFromOrdersDetails(transactionManager, _ordersId, 0, int.MaxValue, out count);
		}
		
		
		/// <summary>
		///		Gets ProductsProduct objects from the datasource by Orders_Id in the
		///		Orders_Details table. Table Products_Product is related to table Orders_Order
		///		through the (M:N) relationship defined in the Orders_Details table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_ordersId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Products_Product objects.</returns>
		public TList<ProductsProduct> GetByOrdersIdFromOrdersDetails(TransactionManager transactionManager, System.Int32 _ordersId,int start, int pageLength)
		{
			int count = -1;
			return GetByOrdersIdFromOrdersDetails(transactionManager, _ordersId, start, pageLength, out count);
		}
		
		/// <summary>
		///		Gets ProductsProduct objects from the datasource by Orders_Id in the
		///		Orders_Details table. Table Products_Product is related to table Orders_Order
		///		through the (M:N) relationship defined in the Orders_Details table.
		/// </summary>
		/// <param name="_ordersId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of Products_Product objects.</returns>
		public TList<ProductsProduct> GetByOrdersIdFromOrdersDetails(System.Int32 _ordersId,int start, int pageLength, out int count)
		{
			
			return GetByOrdersIdFromOrdersDetails(null, _ordersId, start, pageLength, out count);
		}


		/// <summary>
		///		Gets Products_Product objects from the datasource by Orders_Id in the
		///		Orders_Details table. Table Products_Product is related to table Orders_Order
		///		through the (M:N) relationship defined in the Orders_Details table.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <param name="_ordersId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a TList of ProductsProduct objects.</returns>
		public abstract TList<ProductsProduct> GetByOrdersIdFromOrdersDetails(TransactionManager transactionManager,System.Int32 _ordersId, int start, int pageLength, out int count);
		
		#endregion GetByOrdersIdFromOrdersDetails
		
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, Dienthoai.Entities.ProductsProductKey key)
		{
			return Delete(transactionManager, key.ProductsId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_productsId">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Int32 _productsId)
		{
			return Delete(null, _productsId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_productsId">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Int32 _productsId);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override Dienthoai.Entities.ProductsProduct Get(TransactionManager transactionManager, Dienthoai.Entities.ProductsProductKey key, int start, int pageLength)
		{
			return GetByProductsId(transactionManager, key.ProductsId, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_Products_Product index.
		/// </summary>
		/// <param name="_productsId"></param>
		/// <returns>Returns an instance of the <see cref="Dienthoai.Entities.ProductsProduct"/> class.</returns>
		public Dienthoai.Entities.ProductsProduct GetByProductsId(System.Int32 _productsId)
		{
			int count = -1;
			return GetByProductsId(null,_productsId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_Products_Product index.
		/// </summary>
		/// <param name="_productsId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="Dienthoai.Entities.ProductsProduct"/> class.</returns>
		public Dienthoai.Entities.ProductsProduct GetByProductsId(System.Int32 _productsId, int start, int pageLength)
		{
			int count = -1;
			return GetByProductsId(null, _productsId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_Products_Product index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_productsId"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="Dienthoai.Entities.ProductsProduct"/> class.</returns>
		public Dienthoai.Entities.ProductsProduct GetByProductsId(TransactionManager transactionManager, System.Int32 _productsId)
		{
			int count = -1;
			return GetByProductsId(transactionManager, _productsId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_Products_Product index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_productsId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="Dienthoai.Entities.ProductsProduct"/> class.</returns>
		public Dienthoai.Entities.ProductsProduct GetByProductsId(TransactionManager transactionManager, System.Int32 _productsId, int start, int pageLength)
		{
			int count = -1;
			return GetByProductsId(transactionManager, _productsId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_Products_Product index.
		/// </summary>
		/// <param name="_productsId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="Dienthoai.Entities.ProductsProduct"/> class.</returns>
		public Dienthoai.Entities.ProductsProduct GetByProductsId(System.Int32 _productsId, int start, int pageLength, out int count)
		{
			return GetByProductsId(null, _productsId, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_Products_Product index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_productsId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="Dienthoai.Entities.ProductsProduct"/> class.</returns>
		public abstract Dienthoai.Entities.ProductsProduct GetByProductsId(TransactionManager transactionManager, System.Int32 _productsId, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;ProductsProduct&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;ProductsProduct&gt;"/></returns>
		public static TList<ProductsProduct> Fill(IDataReader reader, TList<ProductsProduct> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				Dienthoai.Entities.ProductsProduct c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("ProductsProduct")
					.Append("|").Append((System.Int32)reader[((int)ProductsProductColumn.ProductsId - 1)]).ToString();
					c = EntityManager.LocateOrCreate<ProductsProduct>(
					key.ToString(), // EntityTrackingKey
					"ProductsProduct",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new Dienthoai.Entities.ProductsProduct();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.ProductsId = (System.Int32)reader[((int)ProductsProductColumn.ProductsId - 1)];
					c.ProductsName = (System.String)reader[((int)ProductsProductColumn.ProductsName - 1)];
					c.ProductsTitle = (System.String)reader[((int)ProductsProductColumn.ProductsTitle - 1)];
					c.ProductsQuantity = (reader.IsDBNull(((int)ProductsProductColumn.ProductsQuantity - 1)))?null:(System.Int32?)reader[((int)ProductsProductColumn.ProductsQuantity - 1)];
					c.ProductsPrice = (System.Int32)reader[((int)ProductsProductColumn.ProductsPrice - 1)];
					c.ProductsUnit = (reader.IsDBNull(((int)ProductsProductColumn.ProductsUnit - 1)))?null:(System.String)reader[((int)ProductsProductColumn.ProductsUnit - 1)];
					c.ClassId = (System.Int32)reader[((int)ProductsProductColumn.ClassId - 1)];
					c.BrandId = (System.Int32)reader[((int)ProductsProductColumn.BrandId - 1)];
					c.CategoryId = (System.Int32)reader[((int)ProductsProductColumn.CategoryId - 1)];
					c.ProductsDetail = (reader.IsDBNull(((int)ProductsProductColumn.ProductsDetail - 1)))?null:(System.String)reader[((int)ProductsProductColumn.ProductsDetail - 1)];
					c.ProductsWarranty = (reader.IsDBNull(((int)ProductsProductColumn.ProductsWarranty - 1)))?null:(System.String)reader[((int)ProductsProductColumn.ProductsWarranty - 1)];
					c.ProductsImage = (reader.IsDBNull(((int)ProductsProductColumn.ProductsImage - 1)))?null:(System.String)reader[((int)ProductsProductColumn.ProductsImage - 1)];
					c.ProductsOrigin = (reader.IsDBNull(((int)ProductsProductColumn.ProductsOrigin - 1)))?null:(System.String)reader[((int)ProductsProductColumn.ProductsOrigin - 1)];
					c.ProductsDescriptionImage = (reader.IsDBNull(((int)ProductsProductColumn.ProductsDescriptionImage - 1)))?null:(System.String)reader[((int)ProductsProductColumn.ProductsDescriptionImage - 1)];
					c.QuantityImport = (reader.IsDBNull(((int)ProductsProductColumn.QuantityImport - 1)))?null:(System.Int32?)reader[((int)ProductsProductColumn.QuantityImport - 1)];
					c.QuantityCurrent = (reader.IsDBNull(((int)ProductsProductColumn.QuantityCurrent - 1)))?null:(System.Int32?)reader[((int)ProductsProductColumn.QuantityCurrent - 1)];
					c.ProductsDateUpdate = (reader.IsDBNull(((int)ProductsProductColumn.ProductsDateUpdate - 1)))?null:(System.DateTime?)reader[((int)ProductsProductColumn.ProductsDateUpdate - 1)];
					c.IsActive = (reader.IsDBNull(((int)ProductsProductColumn.IsActive - 1)))?null:(System.Boolean?)reader[((int)ProductsProductColumn.IsActive - 1)];
					c.Ishot = (reader.IsDBNull(((int)ProductsProductColumn.Ishot - 1)))?null:(System.Boolean?)reader[((int)ProductsProductColumn.Ishot - 1)];
					c.IsNew = (reader.IsDBNull(((int)ProductsProductColumn.IsNew - 1)))?null:(System.Boolean?)reader[((int)ProductsProductColumn.IsNew - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="Dienthoai.Entities.ProductsProduct"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="Dienthoai.Entities.ProductsProduct"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, Dienthoai.Entities.ProductsProduct entity)
		{
			if (!reader.Read()) return;
			
			entity.ProductsId = (System.Int32)reader[((int)ProductsProductColumn.ProductsId - 1)];
			entity.ProductsName = (System.String)reader[((int)ProductsProductColumn.ProductsName - 1)];
			entity.ProductsTitle = (System.String)reader[((int)ProductsProductColumn.ProductsTitle - 1)];
			entity.ProductsQuantity = (reader.IsDBNull(((int)ProductsProductColumn.ProductsQuantity - 1)))?null:(System.Int32?)reader[((int)ProductsProductColumn.ProductsQuantity - 1)];
			entity.ProductsPrice = (System.Int32)reader[((int)ProductsProductColumn.ProductsPrice - 1)];
			entity.ProductsUnit = (reader.IsDBNull(((int)ProductsProductColumn.ProductsUnit - 1)))?null:(System.String)reader[((int)ProductsProductColumn.ProductsUnit - 1)];
			entity.ClassId = (System.Int32)reader[((int)ProductsProductColumn.ClassId - 1)];
			entity.BrandId = (System.Int32)reader[((int)ProductsProductColumn.BrandId - 1)];
			entity.CategoryId = (System.Int32)reader[((int)ProductsProductColumn.CategoryId - 1)];
			entity.ProductsDetail = (reader.IsDBNull(((int)ProductsProductColumn.ProductsDetail - 1)))?null:(System.String)reader[((int)ProductsProductColumn.ProductsDetail - 1)];
			entity.ProductsWarranty = (reader.IsDBNull(((int)ProductsProductColumn.ProductsWarranty - 1)))?null:(System.String)reader[((int)ProductsProductColumn.ProductsWarranty - 1)];
			entity.ProductsImage = (reader.IsDBNull(((int)ProductsProductColumn.ProductsImage - 1)))?null:(System.String)reader[((int)ProductsProductColumn.ProductsImage - 1)];
			entity.ProductsOrigin = (reader.IsDBNull(((int)ProductsProductColumn.ProductsOrigin - 1)))?null:(System.String)reader[((int)ProductsProductColumn.ProductsOrigin - 1)];
			entity.ProductsDescriptionImage = (reader.IsDBNull(((int)ProductsProductColumn.ProductsDescriptionImage - 1)))?null:(System.String)reader[((int)ProductsProductColumn.ProductsDescriptionImage - 1)];
			entity.QuantityImport = (reader.IsDBNull(((int)ProductsProductColumn.QuantityImport - 1)))?null:(System.Int32?)reader[((int)ProductsProductColumn.QuantityImport - 1)];
			entity.QuantityCurrent = (reader.IsDBNull(((int)ProductsProductColumn.QuantityCurrent - 1)))?null:(System.Int32?)reader[((int)ProductsProductColumn.QuantityCurrent - 1)];
			entity.ProductsDateUpdate = (reader.IsDBNull(((int)ProductsProductColumn.ProductsDateUpdate - 1)))?null:(System.DateTime?)reader[((int)ProductsProductColumn.ProductsDateUpdate - 1)];
			entity.IsActive = (reader.IsDBNull(((int)ProductsProductColumn.IsActive - 1)))?null:(System.Boolean?)reader[((int)ProductsProductColumn.IsActive - 1)];
			entity.Ishot = (reader.IsDBNull(((int)ProductsProductColumn.Ishot - 1)))?null:(System.Boolean?)reader[((int)ProductsProductColumn.Ishot - 1)];
			entity.IsNew = (reader.IsDBNull(((int)ProductsProductColumn.IsNew - 1)))?null:(System.Boolean?)reader[((int)ProductsProductColumn.IsNew - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="Dienthoai.Entities.ProductsProduct"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="Dienthoai.Entities.ProductsProduct"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, Dienthoai.Entities.ProductsProduct entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.ProductsId = (System.Int32)dataRow["Products_Id"];
			entity.ProductsName = (System.String)dataRow["Products_Name"];
			entity.ProductsTitle = (System.String)dataRow["Products_Title"];
			entity.ProductsQuantity = Convert.IsDBNull(dataRow["Products_Quantity"]) ? null : (System.Int32?)dataRow["Products_Quantity"];
			entity.ProductsPrice = (System.Int32)dataRow["Products_Price"];
			entity.ProductsUnit = Convert.IsDBNull(dataRow["Products_Unit"]) ? null : (System.String)dataRow["Products_Unit"];
			entity.ClassId = (System.Int32)dataRow["Class_Id"];
			entity.BrandId = (System.Int32)dataRow["Brand_Id"];
			entity.CategoryId = (System.Int32)dataRow["Category_Id"];
			entity.ProductsDetail = Convert.IsDBNull(dataRow["Products_Detail"]) ? null : (System.String)dataRow["Products_Detail"];
			entity.ProductsWarranty = Convert.IsDBNull(dataRow["Products_Warranty"]) ? null : (System.String)dataRow["Products_Warranty"];
			entity.ProductsImage = Convert.IsDBNull(dataRow["Products_Image"]) ? null : (System.String)dataRow["Products_Image"];
			entity.ProductsOrigin = Convert.IsDBNull(dataRow["Products_Origin"]) ? null : (System.String)dataRow["Products_Origin"];
			entity.ProductsDescriptionImage = Convert.IsDBNull(dataRow["Products_DescriptionImage"]) ? null : (System.String)dataRow["Products_DescriptionImage"];
			entity.QuantityImport = Convert.IsDBNull(dataRow["QuantityImport"]) ? null : (System.Int32?)dataRow["QuantityImport"];
			entity.QuantityCurrent = Convert.IsDBNull(dataRow["QuantityCurrent"]) ? null : (System.Int32?)dataRow["QuantityCurrent"];
			entity.ProductsDateUpdate = Convert.IsDBNull(dataRow["Products_DateUpdate"]) ? null : (System.DateTime?)dataRow["Products_DateUpdate"];
			entity.IsActive = Convert.IsDBNull(dataRow["IsActive"]) ? null : (System.Boolean?)dataRow["IsActive"];
			entity.Ishot = Convert.IsDBNull(dataRow["Ishot"]) ? null : (System.Boolean?)dataRow["Ishot"];
			entity.IsNew = Convert.IsDBNull(dataRow["IsNew"]) ? null : (System.Boolean?)dataRow["IsNew"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="Dienthoai.Entities.ProductsProduct"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">Dienthoai.Entities.ProductsProduct Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, Dienthoai.Entities.ProductsProduct entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			// Deep load child collections  - Call GetByProductsId methods when available
			
			#region OrdersIdOrdersOrderCollection_From_OrdersDetails
			// RelationshipType.ManyToMany
			if (CanDeepLoad(entity, "List<OrdersOrder>|OrdersIdOrdersOrderCollection_From_OrdersDetails", deepLoadType, innerList))
			{
				entity.OrdersIdOrdersOrderCollection_From_OrdersDetails = DataRepository.OrdersOrderProvider.GetByProductsIdFromOrdersDetails(transactionManager, entity.ProductsId);			 
		
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'OrdersIdOrdersOrderCollection_From_OrdersDetails' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.OrdersIdOrdersOrderCollection_From_OrdersDetails != null)
				{
					deepHandles.Add("OrdersIdOrdersOrderCollection_From_OrdersDetails",
						new KeyValuePair<Delegate, object>((DeepLoadHandle< OrdersOrder >) DataRepository.OrdersOrderProvider.DeepLoad,
						new object[] { transactionManager, entity.OrdersIdOrdersOrderCollection_From_OrdersDetails, deep, deepLoadType, childTypes, innerList }
					));
				}
			}
			#endregion
			
			
			
			#region OrdersDetailsCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<OrdersDetails>|OrdersDetailsCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'OrdersDetailsCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.OrdersDetailsCollection = DataRepository.OrdersDetailsProvider.GetByProductsId(transactionManager, entity.ProductsId);

				if (deep && entity.OrdersDetailsCollection.Count > 0)
				{
					deepHandles.Add("OrdersDetailsCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<OrdersDetails>) DataRepository.OrdersDetailsProvider.DeepLoad,
						new object[] { transactionManager, entity.OrdersDetailsCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the Dienthoai.Entities.ProductsProduct object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">Dienthoai.Entities.ProductsProduct instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">Dienthoai.Entities.ProductsProduct Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, Dienthoai.Entities.ProductsProduct entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();

			#region OrdersIdOrdersOrderCollection_From_OrdersDetails>
			if (CanDeepSave(entity.OrdersIdOrdersOrderCollection_From_OrdersDetails, "List<OrdersOrder>|OrdersIdOrdersOrderCollection_From_OrdersDetails", deepSaveType, innerList))
			{
				if (entity.OrdersIdOrdersOrderCollection_From_OrdersDetails.Count > 0 || entity.OrdersIdOrdersOrderCollection_From_OrdersDetails.DeletedItems.Count > 0)
				{
					DataRepository.OrdersOrderProvider.Save(transactionManager, entity.OrdersIdOrdersOrderCollection_From_OrdersDetails); 
					deepHandles.Add("OrdersIdOrdersOrderCollection_From_OrdersDetails",
						new KeyValuePair<Delegate, object>((DeepSaveHandle<OrdersOrder>) DataRepository.OrdersOrderProvider.DeepSave,
						new object[] { transactionManager, entity.OrdersIdOrdersOrderCollection_From_OrdersDetails, deepSaveType, childTypes, innerList }
					));
				}
			}
			#endregion 
	
			#region List<OrdersDetails>
				if (CanDeepSave(entity.OrdersDetailsCollection, "List<OrdersDetails>|OrdersDetailsCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(OrdersDetails child in entity.OrdersDetailsCollection)
					{
						if(child.ProductsIdSource != null)
						{
								child.ProductsId = child.ProductsIdSource.ProductsId;
						}

						if(child.OrdersIdSource != null)
						{
								child.OrdersId = child.OrdersIdSource.OrderId;
						}

					}

					if (entity.OrdersDetailsCollection.Count > 0 || entity.OrdersDetailsCollection.DeletedItems.Count > 0)
					{
						//DataRepository.OrdersDetailsProvider.Save(transactionManager, entity.OrdersDetailsCollection);
						
						deepHandles.Add("OrdersDetailsCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< OrdersDetails >) DataRepository.OrdersDetailsProvider.DeepSave,
							new object[] { transactionManager, entity.OrdersDetailsCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region ProductsProductChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>Dienthoai.Entities.ProductsProduct</c>
	///</summary>
	public enum ProductsProductChildEntityTypes
	{
		///<summary>
		/// Collection of <c>ProductsProduct</c> as ManyToMany for OrdersOrderCollection_From_OrdersDetails
		///</summary>
		[ChildEntityType(typeof(TList<OrdersOrder>))]
		OrdersIdOrdersOrderCollection_From_OrdersDetails,
		///<summary>
		/// Collection of <c>ProductsProduct</c> as OneToMany for OrdersDetailsCollection
		///</summary>
		[ChildEntityType(typeof(TList<OrdersDetails>))]
		OrdersDetailsCollection,
	}
	
	#endregion ProductsProductChildEntityTypes
	
	#region ProductsProductFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;ProductsProductColumn&gt;"/> class
	/// that is used exclusively with a <see cref="ProductsProduct"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class ProductsProductFilterBuilder : SqlFilterBuilder<ProductsProductColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the ProductsProductFilterBuilder class.
		/// </summary>
		public ProductsProductFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the ProductsProductFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public ProductsProductFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the ProductsProductFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public ProductsProductFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion ProductsProductFilterBuilder
	
	#region ProductsProductParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;ProductsProductColumn&gt;"/> class
	/// that is used exclusively with a <see cref="ProductsProduct"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class ProductsProductParameterBuilder : ParameterizedSqlFilterBuilder<ProductsProductColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the ProductsProductParameterBuilder class.
		/// </summary>
		public ProductsProductParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the ProductsProductParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public ProductsProductParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the ProductsProductParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public ProductsProductParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion ProductsProductParameterBuilder
	
	#region ProductsProductSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;ProductsProductColumn&gt;"/> class
	/// that is used exclusively with a <see cref="ProductsProduct"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class ProductsProductSortBuilder : SqlSortBuilder<ProductsProductColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the ProductsProductSqlSortBuilder class.
		/// </summary>
		public ProductsProductSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion ProductsProductSortBuilder
	
} // end namespace
